<?php

class Ext_Register
{
    protected static $_instance = null;
    protected $_validater = null;
    protected $_signUper = null;
    
    public static function getInstance()
    {
        if (null === self::$_instance) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }
    
    public function __construct($controller)
    {
        $this->_controller = $controller;
    }
    
    public function showForm()
    {
        $_postForm = new Ext_Register_ShowForm_Adapter($this->_controller);
        $_postForm->showForm();
    }
    
    public function validate()
    {
        $_validater = new Ext_Register_Validate_Adapter($this->_controller);
        $_validater->getAdapter()->validate();

        $this->_validater = $_validater;
    }
    
    public function getValidater()
    {
        return $this->_validater->getAdapter();
    }
    
    public function signUp()
    {
        $_signUper = new Ext_Register_SignUp_Adapter($this->getValidater()->getResult()->getData());
        $_signUper->getAdapter()->signUp();
        
        $this->_signUper = $_signUper;
    }
    
    public function getSignUper()
    {
        return $this->_signUper->getAdapter();
    }
    
    public function oauth()
    {
        if($this->getValidater()->isOauth())
        {
            $_oauth = Ext_Oauth::getInstance();
            $_oauth->setBind($this->getSignUper()->getResult()->getIdentity());
        }
    }
    
    public function auth()
    {
        $_auther = Ext_Auth::getInstance();
        $_auther->auth($this->getSignUper()->getResult()->getIdentity());
    }
}
